# Load green house emissions data
country_ghg_emissions <-
read_csv('../data/raw/CAIT-Country-GHG-Emissions.csv', skip=2) %>%
clean_names()
# Avg emissions of all types per country
country_avg_emissions <- country_ghg_emissions %>%
select(-year) %>%
filter(country != 'World', !str_detect(country, 'European Union')) %>%
group_by(country) %>%
summarise_each(list(mean = mean))
# Barplot of top 20 countries avg ghg emission
country_avg_emissions %>%
rename(avg_ghg_emissions = total_ghg_emissions_including_land_use_change_and_forestry_mt_co_e_mean) %>%
top_n(20, wt=avg_ghg_emissions) %>%
ggplot(aes(reorder(country, avg_ghg_emissions), avg_ghg_emissions)) +
geom_bar(stat='identity') +
coord_flip() +
labs(
title = 'Top 20 countries based on their average GHG emissions',
x = 'Country',
y = 'Average GHG emission per year (MtCO2e)'
) +
theme_hc()
From the plot above, US and China are by far the heaviest producers of GHG. Thus we will limit our analysis to US, China, India and Canada.
countries_of_interest <-
tribble(
~country,
'United States',
'China',
'India',
'Canada'
)
# GHG emissions for countries of interest only
p <- countries_of_interest %>%
inner_join(country_ghg_emissions,by='country') %>%
ggplot(aes(x=year, y=total_ghg_emissions_including_land_use_change_and_forestry_mt_co_e, colour=country)) +
geom_line() +
geom_point() +
labs(
title = 'GHG emission per country',
y = 'GHG emission (MtCO2e)',
x = 'Year',
colour = 'Country'
)
ggplotly(p)
The above graph displays the ghg emissions over time for our countries of interest. China has climbed greatly over the last decade while the other countries don’t seem to have changed as much.
For this analysis, we will be going through each country individually, starting with Canada.
# TODO: Figure out way to cleanly store this as a tibble
regulations <- read_csv('../data/raw/law_search/data.csv') %>%
clean_names() %>%
rename(year = year_passed) %>%
mutate(categories = categories %>%
str_to_lower() %>%
str_replace_all('energy supply|energy demand', 'energy') %>%
str_replace_all('; ', ';') %>%
str_split(';')) %>%
mutate(categories = map(categories, unique))
regulation_category_types <- regulations %>%
select(categories) %>%
unlist() %>%
str_trim() %>%
unique()
# Data from Stats Can, most likely the best data for Canada GHG Emissions
# TODO: find a way to replace mt_co2e in all column names
canada_ghg_emissions <- read_csv('../data/raw/GHG-emissions-sector-en.csv', skip=2) %>%
clean_names() %>%
filter(!str_detect(year, 'Note|Source|Available')) %>%
mutate(year = as.integer(year)) %>%
pivot_longer(cols=-year, names_to='category', values_to='mt_co2e')
# NOTE: Oil and gas is equivalent to carbon pricing?
canada_category_mappings <-
tribble(
~canada_category, ~regulation_category,
'oil_and_gas_megatonnes_of_carbon_dioxide_equivalent', 'carbon pricing',
'transportation_megatonnes_of_carbon_dioxide_equivalent', 'transportation',
'buildings_megatonnes_of_carbon_dioxide_equivalent', 'buildings',
'electricity_megatonnes_of_carbon_dioxide_equivalent', 'energy',
'heavy_industry_megatonnes_of_carbon_dioxide_equivalent', 'industry',
'waste_and_others_megatonnes_of_carbon_dioxide_equivalent', 'waste'
)
# Canada regulations and their corresponding mtco2 values for that given year
canada_regulations <- regulations %>%
filter(country == 'Canada') %>%
unnest_longer(categories) %>%
left_join(canada_category_mappings, by=c('categories' = 'regulation_category')) %>%
left_join(canada_ghg_emissions, by=c('year' = 'year', 'canada_category' = 'category'))
# Display time series of canada ghg emission per subsector, along with corresponding regulations
p <- canada_ghg_emissions %>%
mutate(category = str_remove(category, '_megatonnes_of_carbon_dioxide_equivalent')) %>%
mutate(category = str_replace_all(category, '_', ' ')) %>%
ggplot(aes(x=year, y=mt_co2e)) +
geom_line(aes(colour=category)) +
geom_point(
data = canada_regulations,
aes(x = year, y = mt_co2e)
) +
# geom_text_repel(
# data = canada_regulations,
# aes(x = year, y = mt_co2e, label = name),
# size = 3
# ) +
labs(
title = 'Canada GHG emissions per subsector and corresponding regulations',
x = 'Year',
y = 'GHG emissions (megatonnes of CO2 equivalent)',
colour = 'Category'
) +
theme_hc()
ggplotly(p)
canada_electricity_ghg <- canada_ghg_emissions %>%
filter(str_detect(category, 'electricity')) %>%
select(-category)
# Plot ghg emission with regulation names
canada_electricity_ghg %>%
ggplot(aes(x=year, y=mt_co2e)) +
geom_line() +
geom_point(
data = canada_regulations %>% filter(categories == 'energy'),
aes(x=year, y=mt_co2e)
) +
geom_text_repel(
data = canada_regulations %>% filter(categories == 'energy'),
aes(x=year, y=mt_co2e, label=name)
) +
labs(
title = 'Canada GHG emission from electricity and corresponding regulations',
x = 'Year',
y = 'GHG emission (megatonnes of CO2 equivalent)'
) +
theme_minimal()
sessionInfo()
## R version 3.6.1 (2019-07-05)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 17763)
##
## Matrix products: default
##
## locale:
## [1] LC_COLLATE=English_Canada.1252 LC_CTYPE=English_Canada.1252
## [3] LC_MONETARY=English_Canada.1252 LC_NUMERIC=C
## [5] LC_TIME=English_Canada.1252
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] forcats_0.4.0 stringr_1.4.0 dplyr_0.8.3
## [4] purrr_0.3.2 readr_1.3.1 tidyr_1.0.0
## [7] tibble_2.1.3 tidyverse_1.2.1 skimr_1.0.7
## [10] plyr_1.8.4 plotly_4.9.1 lubridate_1.7.4
## [13] janitor_1.2.0 ggthemes_4.2.0 ggrepel_0.8.1
## [16] ggplot2_3.2.1 countrycode_1.1.0
##
## loaded via a namespace (and not attached):
## [1] Rcpp_1.0.2 lattice_0.20-38 assertthat_0.2.1
## [4] zeallot_0.1.0 digest_0.6.20 mime_0.7
## [7] R6_2.4.0 cellranger_1.1.0 backports_1.1.4
## [10] evaluate_0.14 httr_1.4.1 pillar_1.4.2
## [13] rlang_0.4.0 lazyeval_0.2.2 readxl_1.3.1
## [16] rstudioapi_0.10 data.table_1.12.6 rmarkdown_1.15
## [19] labeling_0.3 htmlwidgets_1.5.1 munsell_0.5.0
## [22] shiny_1.4.0 broom_0.5.2 compiler_3.6.1
## [25] httpuv_1.5.2 modelr_0.1.5 xfun_0.9
## [28] pkgconfig_2.0.2 htmltools_0.4.0 tidyselect_0.2.5
## [31] viridisLite_0.3.0 crayon_1.3.4 withr_2.1.2
## [34] later_1.0.0 grid_3.6.1 xtable_1.8-4
## [37] nlme_3.1-140 jsonlite_1.6 gtable_0.3.0
## [40] lifecycle_0.1.0 magrittr_1.5 scales_1.0.0
## [43] cli_1.1.0 stringi_1.4.3 promises_1.1.0
## [46] snakecase_0.11.0 xml2_1.2.2 generics_0.0.2
## [49] vctrs_0.2.0 tools_3.6.1 glue_1.3.1
## [52] hms_0.5.1 crosstalk_1.0.0 fastmap_1.0.1
## [55] yaml_2.2.0 colorspace_1.4-1 rvest_0.3.4
## [58] knitr_1.24 haven_2.1.1